//
//  WJWeatherTableViewCell.m
//  天气
//
//  Created by dllo on 16/8/23.
//  Copyright © 2016年 WJ. All rights reserved.
//

#import "WJWeatherTableViewCell.h"
#import "WJTitleLable.h"
#import "WJWeatherCollectionViewCell.h"
#define kWJWidth  [UIScreen mainScreen].bounds.size.width
#define kWJHeight [UIScreen mainScreen].bounds.size.height

@interface WJWeatherTableViewCell ()<UICollectionViewDataSource,UICollectionViewDelegate>


@end


@implementation WJWeatherTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.35];
        [self createView];
        
    }
    return self;
}

- (void)createView
{
    WJTitleLable *contentLabel = [[WJTitleLable alloc]initWithFrame:CGRectMake(20, 0, kWJWidth - 40, 30)];
    contentLabel.text = @"24小时天气";
    contentLabel.textAlignment = 0;
    [self.contentView addSubview:contentLabel];
    
    // 创建 flowLayout
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
    flowLayout.itemSize = CGSizeMake(40, 100);
    flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    flowLayout.minimumLineSpacing = 10;
    flowLayout.minimumInteritemSpacing = 0;
    flowLayout.sectionInset = UIEdgeInsetsMake(0, 10, 0, 10);
    
    // 创建CollectiobView
    self.collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 50, kWJWidth, 100) collectionViewLayout:flowLayout];
    [self.contentView addSubview:self.collectionView ];
    self.collectionView .backgroundColor = [UIColor clearColor];
    self.collectionView .delegate = self;
    self.collectionView .dataSource = self;
    self.collectionView.bounces = NO;
    /* 注册cell的重用池 */
    [self.collectionView  registerClass:[WJWeatherCollectionViewCell class] forCellWithReuseIdentifier:@"WJWeatherCollectionViewCell"];
    
}
//item的个数(方块的个数)
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    
    if (self.hourly_forecast.count) {
        
        return self.hourly_forecast.count;
        
    }else{
        
        return 0;
    }
}

//cell的样式(可以自定义)
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    WJWeatherCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"WJWeatherCollectionViewCell" forIndexPath:indexPath];
    
    if (self.hourly_forecast.count) {
        cell.dic = self.hourly_forecast[indexPath.row];
    }
    
    return cell;
}





































































































































































- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
}
@end
